//
//  SJRegularDetectionTool.m
//  Init
//
//  Created by zhaoshijie on 05/02/2018.
//  Copyright © 2018 zhaoshijie. All rights reserved.
//

#import "SJRegularDetectionTool.h"

@implementation SJRegularDetectionTool


/**
 11位的手机号码

 @param phone 手机号码
 @return 检测结果
 */
+ (BOOL)regularDetectionWithPhone:(NSString *)phone
{
    //  正则表达式
    NSString *regex = @"^((13[0-9])|(15[^4,\\D])|(18[0,0-9]))\\d{8}$";
    //  创建谓词对象,并设定条件的表达式
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    //  对字符串进行判断
    if ([predicate evaluateWithObject:phone])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}


/**
 中文、英文、数字但不包括下划线等符号
 
 @param string 手机号码
 @return 检测结果
 */
+ (BOOL)regularDetectionWithChineseEnglishAndNumberWithString:(NSString *)string
{
    
    //  正则表达式   ^[\u4E00-\u9FA5A-Za-z0-9]+$ 或 ^[\u4E00-\u9FA5A-Za-z0-9]{2,20}$
    NSString *regex = @"^[\u4E00-\u9FA5A-Za-z0-9]+$";
    //  创建谓词对象,并设定条件的表达式
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    //  对字符串进行判断
    if ([predicate evaluateWithObject:string])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}


/**
 判断密码格式
 
 @param passwordString 密码
 @return 结果
 */
+ (BOOL)regularDetectionWithPasswordString:(NSString *)passwordString
{
    BOOL result = false;
    
    // 判断长度6-16位后是否同时包含数字和字符
    NSString * regex = @"^[a-z0-9A-Z]{6,16}$";
    NSPredicate *pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    result = [pred evaluateWithObject:passwordString];
    
    
    return result;
    
}



/**
 判断身份证格式

 @param IDCardNumber 身份证
 @return 结果
 */
+ (BOOL)regularDetectionWithIdentityCard:(NSString *)IDCardNumber
{
    if (IDCardNumber.length <= 0) {
        return NO;
    }
    NSString *regex2 = @"^(\\d{14}|\\d{17})(\\d|[xX])$";
    NSPredicate *identityCardPredicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",regex2];
    return [identityCardPredicate evaluateWithObject:IDCardNumber];
}




/**
 判断银行卡格式

 @param cardNumber 银行卡
 @return 结果
 */
+ (BOOL) regularDetectionWithBankCard:(NSString *)cardNumber
{
    //  正则表达式
    NSString *regex = @"^\\d{14,19}$";
    //  创建谓词对象,并设定条件的表达式
    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    //  对字符串进行判断
    if ([predicate evaluateWithObject:cardNumber])
    {
        return YES;
    }
    else
    {
        return NO;
    }
}



@end
